package com.neu.his.scheduling.controller;

import java.util.ArrayList;
import java.util.List;

import org.ehcache.spi.service.ServiceConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neu.his.commonutils.R;
import com.neu.his.scheduling.entity.DeptUser;
import com.neu.his.scheduling.entity.DeptVo;
import com.neu.his.scheduling.entity.Rule;
import com.neu.his.scheduling.entity.UserRoleVo;
import com.neu.his.scheduling.service.SchedulingService;
import com.neu.his.user.service.UserService;
import com.neu.his.user.serviceimpl.UserServiceImpl;
@CrossOrigin
@RestController
@RequestMapping("/his/scheduling")
public class SchedulingController {
	@Autowired
	private SchedulingService schedulingService;
//	获取所有课室列表
	@GetMapping("/getDeptList")
		public R getDeptList() {
		List<DeptVo> list =schedulingService.getDeptList();
			return R.ok().data("list", list);
			
		}
//	获取指定科室可排班的医生列表
	@GetMapping("/getUserRole")
		public R getUserRole(int deptID) {
		List<UserRoleVo> list=schedulingService.getUserRole(deptID);
			return R.ok().data("list",list);
			
		}
//	获取所有的医生排班的规则
	@GetMapping("/getAllUserRole")
		public R getAllUserRole() {
		List<UserRoleVo> list=schedulingService.getAllUserRole();
			return R.ok().data("list", list);
						
	}
//	修改排班规则的方法
	@PostMapping("/updateRole")
		public R updateRole(@RequestBody UserRoleVo userRoleVo) {
		boolean flag =schedulingService.updateRole(userRoleVo);
		if(flag) {
			return R.ok().message("修改成功");
		}
		return R.error();
	}
//	根据科室查找用户
	@GetMapping("/getUserByDeptID")
		public R getUserByDeptID(int deptID) {
		List<DeptUser> list=schedulingService.getUserByDeptID(deptID);
			return R.ok().data("list", list);
			
	}
//	添加一个排班规则
	@PostMapping("/addRule")
		public R addRole(@RequestBody Rule rule) {
		boolean flag=schedulingService.addRule(rule);
		if(flag) {
			return R.ok();
	
	}
		return R.error();
}
}
